import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import {logger} from './middleware/logger/logger.middleware'
import * as express from'express';
import { TransformInterceptor } from'./interceptor/transform/transform.interceptor';
import { HttpExceptionFilter } from './filter/http-exception/http-exception.filter';
import { AllExceptionsFilter } from './filter/any-exception/any-exception.filter';
import {NestExpressApplication} from "@nestjs/platform-express";

declare const module: any
async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);//使用nest的工厂函数创建了AppModule
  app.use(express.json());
  app.use(express.urlencoded({extended:true}));
  // 监听所有的请求路由，并打印日志
  app.use(logger);
  // 使用全局拦截器打印出参
  app.useGlobalInterceptors(new TransformInterceptor());

  // app.setGlobalPrefix('overall-situation');//全局路由前缀
  // 过滤处理http异常
  app.useGlobalFilters(new HttpExceptionFilter());
  app.useGlobalFilters(new AllExceptionsFilter());
  await app.listen(8000);//监听3000端口，自个可以自己设置

  // 热更新
  if (module.hot) {
    module.hot.accept()
    module.hot.dispose(() => app.close())
  }
}
bootstrap();
